package com.yc.chaoshi.cs_order.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.chaoshi.cs_order.mapper.PmsGoodsMapper;
import com.yc.chaoshi.entity.PmsGoods;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.chaoshi.cs_order.DTO.Goodspl;
import com.yc.chaoshi.cs_order.mapper.PmsGoodsMapper;
import com.yc.chaoshi.cs_order.service.impl.PmsGoodsServiceImpl;
import com.yc.chaoshi.entity.PmsGoods;
import com.yc.common.api.CommonResult;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/chaoshi/pmsGoods")
public class PmsGoodsController {

    @Resource
    private PmsGoodsMapper pmsGoodsMapper;

    @RequestMapping("findById")
    public PmsGoods findById(@RequestParam int id){
        return pmsGoodsMapper.selectById(id);
    }


    @RequestMapping("findDiscount")
    public List<PmsGoods> findDiscount(){
        return pmsGoodsMapper.findDiscount();
    }

    @RequestMapping("findHot")
    public List<PmsGoods> findHot(){
        return pmsGoodsMapper.findHot();
    }

    @RequestMapping("findMaxHot")
    public List<PmsGoods> findMaxHot(){
        return pmsGoodsMapper.findMaxHot();
    }

    @RequestMapping("findHotF3")
    public List<PmsGoods> findHotF3(){
        return pmsGoodsMapper.findMaxHot();
    }

    // 商品查询
    @RequestMapping("queryGoods")
    public IPage<PmsGoods> queryGoods(@RequestParam String name,
                                          @RequestParam int page,@RequestParam int size){
        Page<PmsGoods> ipage = new Page<>(page,size);
        System.out.println("name="+name+";page="+page+";size="+size);
        ipage.setRecords(pmsGoodsMapper.queryGoods(name,(page-1)*size,size));
        System.out.println("ipage"+ipage);
        final Map<String,Object> map = pmsGoodsMapper.countGoods(name);
        long total = Long.parseLong(map.get("cnt") + "");
        ipage.setTotal(total);
        return ipage;
    }


    // 大类查询
    @RequestMapping("queryPageByAid")
    public IPage<PmsGoods> queryPageByAid(@RequestParam int aid,
                                         @RequestParam int page,@RequestParam int size){
        Page<PmsGoods> ipage = new Page<>(page,size);
        ipage.setRecords(pmsGoodsMapper.selectByAid(aid,(page-1)*size,size));
        final Map<String,Object> map = pmsGoodsMapper.countByAid(aid);
        long total = Long.parseLong(map.get("cnt") + "");
        ipage.setTotal(total);
        return ipage;
    }

     //二类查询
    @RequestMapping("queryPageByBid")
    public IPage<PmsGoods> queryPageByBid(@RequestParam int bid,
                                          @RequestParam int page, @RequestParam int size){
        Page<PmsGoods> ipage = new Page<>(page,size);
        ipage.setRecords(pmsGoodsMapper.selectByBid(bid,(page-1)*size,size));
        final Map<String,Object> map = pmsGoodsMapper.countByBid(bid);
        long total = Long.parseLong(map.get("cnt") + "");
        ipage.setTotal(total);
        return ipage;
    }


    // 三类查询
    @RequestMapping("queryPageByCid")
    public IPage<PmsGoods> queryPageByCid(@RequestParam int cid,
                                           @RequestParam int page, @RequestParam int size){
        IPage<PmsGoods> ipage = new Page<>(page,size);
        ipage.setRecords(pmsGoodsMapper.selectByCid(cid,(page-1)*size,size));
        final Map<String,Object> map = pmsGoodsMapper.countByCid(cid);
        long total = Long.parseLong(map.get("cnt") + "");
        ipage.setTotal(total);
        return ipage;
    }


    @Resource
    private PmsGoodsMapper pmsGoodsMapper;
    @Resource
    private PmsGoodsServiceImpl goodsService;

    @RequestMapping("findById")
    public PmsGoods findById(@RequestParam int id){
        return pmsGoodsMapper.selectById(id);
    }


    @RequestMapping("findDiscount")
    public List<PmsGoods> findDiscount(){
        return pmsGoodsMapper.findDiscount();
    }

    @RequestMapping("findHot")
    public List<PmsGoods> findHot(){
        return pmsGoodsMapper.findHot();
    }

    @RequestMapping("findMaxHot")
    public List<PmsGoods> findMaxHot(){
        return pmsGoodsMapper.findMaxHot();
    }

    @RequestMapping("findHotF3")
    public List<PmsGoods> findHotF3(){
        return pmsGoodsMapper.findMaxHot();
    }

    // 商品查询
    @RequestMapping("queryGoods")
    public IPage<PmsGoods> queryGoods(@RequestParam String name,
                                          @RequestParam int page,@RequestParam int size){
        Page<PmsGoods> ipage = new Page<>(page,size);
        System.out.println("name="+name+";page="+page+";size="+size);
        ipage.setRecords(pmsGoodsMapper.queryGoods(name,(page-1)*size,size));
        System.out.println("ipage"+ipage);
        final Map<String,Object> map = pmsGoodsMapper.countGoods(name);
        long total = Long.parseLong(map.get("cnt") + "");
        ipage.setTotal(total);
        return ipage;
    }


    // 大类查询
    @RequestMapping("queryPageByAid")
    public IPage<PmsGoods> queryPageByAid(@RequestParam int aid,
                                         @RequestParam int page,@RequestParam int size){
        Page<PmsGoods> ipage = new Page<>(page,size);
        ipage.setRecords(pmsGoodsMapper.selectByAid(aid,(page-1)*size,size));
        final Map<String,Object> map = pmsGoodsMapper.countByAid(aid);
        long total = Long.parseLong(map.get("cnt") + "");
        ipage.setTotal(total);
        return ipage;
    }

     //二类查询
    @RequestMapping("queryPageByBid")
    public IPage<PmsGoods> queryPageByBid(@RequestParam int bid,
                                          @RequestParam int page, @RequestParam int size){
        Page<PmsGoods> ipage = new Page<>(page,size);
        ipage.setRecords(pmsGoodsMapper.selectByBid(bid,(page-1)*size,size));
        final Map<String,Object> map = pmsGoodsMapper.countByBid(bid);
        long total = Long.parseLong(map.get("cnt") + "");
        ipage.setTotal(total);
        return ipage;
    }


    // 三类查询
    @RequestMapping("queryPageByCid")
    public IPage<PmsGoods> queryPageByCid(@RequestParam int cid,
                                           @RequestParam int page, @RequestParam int size){
        IPage<PmsGoods> ipage = new Page<>(page,size);
        ipage.setRecords(pmsGoodsMapper.selectByCid(cid,(page-1)*size,size));
        final Map<String,Object> map = pmsGoodsMapper.countByCid(cid);
        long total = Long.parseLong(map.get("cnt") + "");
        ipage.setTotal(total);
        return ipage;
    }
    @GetMapping("/listgoods/{uid}")
    public CommonResult listgoods(@PathVariable("uid") Integer uid){
           List<Goodspl> list=goodsService.listgoods(uid);
           return CommonResult.success(list);
    }

}

